package dp.ua.epic.pages;

import epic.domain.PathDecision;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.Link;
import org.wicketstuff.annotation.mount.MountPath;

/**
 * Class that responsible for 'Choose' page.
 * 
 * @author Chris
 * @date 26.01.2011 10:30:29
 */
@MountPath(path = "choose")
public class Choose extends BasePage {

    private static final long serialVersionUID = 1L;

    public Choose(final PageParameters parameters) {
        final Link leftLink = new ChooseLink("leftLink", PathDecision.LEFT);
        add(leftLink);

        final Link forwardLink = new ChooseLink("forwardLink", PathDecision.STRAIGHT);
        add(forwardLink);

        final Link rightLink = new ChooseLink("rightLink", PathDecision.RIGHT);
        add(rightLink);
    }
}

/**
 *
 * Link for choosing path decision. With stable markup id's for testing purpose.
 *
 * @author Artem
 */
class ChooseLink extends Link {

    private PageParameters pageParameters;

    public ChooseLink(String id, PathDecision pathDecision) {
        super(id);
        setStableId(id);
        pageParameters = new PageParameters(Chosen.FATE_ID_PARAMETR_NAME + "=" + pathDecision.getDescisionId());
    }

    @Override
    public void onClick() {
        setRedirect(true);
        setResponsePage(Chosen.class, pageParameters);
    }

    private void setStableId(String id) {
        setOutputMarkupId(true);
        setMarkupId(id);
    }
}
